package org.visual.plugin.gme.editors.xml;

import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.MultiLineRule;

public class MashupTagRule extends MultiLineRule {
	private static final String PREFIX = "gm:";

	public MashupTagRule(IToken token) {
		super("<" + PREFIX, ">", token);
	}
	
	protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
		for (int i= 1; i < sequence.length; i++) {
			int c= scanner.read();
			if (c == ICharacterScanner.EOF && eofAllowed) {
				return true;
			} else if (c != sequence[i]) {
				// Non-matching character detected, rewind the scanner back to the start.
				// Do not unread the first character.
				scanner.unread();
				for (int j= i-1; j > 0; j--)
					scanner.unread();
				return false;
			}
		}

		return true;
	}
//	protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence,
//			boolean eofAllowed) {
//		int c = scanner.read();
//		char tmp = (char) c;
//		int i = 1;
//		if (sequence[0] == '<') {
//			while (c != ICharacterScanner.EOF && i < PREFIX.length()
//					&& c == PREFIX.getBytes()[i - 1]) {
//				c = scanner.read();
//				tmp = (char) c;
//				i++;
//			}
//		}
//		if (i == PREFIX.length()) {
//			return true;
//		}
//		for (int o = 0; o < i; o++) {
//			scanner.unread();
//		}
//		return false;
//	}
}
